<?php

class News_Form_News extends Zend_Form {

	public function init() {
		$this->setMethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		
		$subFormName = new Zend_Form_SubForm();
        $subFormName->removeDecorator('Fieldset');
        $subFormContent = new Zend_Form_SubForm();
        $subFormContent->removeDecorator('Fieldset');
        $subFormAnonce = new Zend_Form_SubForm();
        $subFormAnonce->removeDecorator('Fieldset');
        $subFormDescription = new Zend_Form_SubForm();
        $subFormDescription->removeDecorator('Fieldset');
        $subFormKeywords = new Zend_Form_SubForm();
        $subFormKeywords->removeDecorator('Fieldset');
		
		foreach($locales as $lang=>$value) {
			$name = new Zend_Form_Element_Text($lang);
			$name->setLabel(strtoupper($lang) . ' ' . _('Name:'));
			$name->setFilters(array('StringTrim','StripTags'));
			
			$anonce = new ZFEngine_Form_Element_TinyMce($lang);
			$anonce->setLabel(strtoupper($lang) . ' ' . _('Anonce:'));
			$anonce->setFilters(array('StringTrim'));
			$anonce->setAttrib('editorOptions', array('theme' => 'advanced'));
			
			$content = new ZFEngine_Form_Element_TinyMce($lang);
			$content->setLabel(strtoupper($lang) . ' ' . _('Content:'));
			$content->setFilters(array('StringTrim'));
			$content->setAttrib('editorOptions', array('theme' => 'advanced'));
			
			$description = new Zend_Form_Element_Textarea($lang);
			$description->setLabel(strtoupper($lang) . ' ' . _('Seo Description:'));
			$description->setFilters(array('StringTrim'));
			
			$keywords = new Zend_Form_Element_Textarea($lang);
			$keywords->setLabel(strtoupper($lang) . ' ' . _('Seo Keywords:'));
			$keywords->setFilters(array('StringTrim'));
			
			if($defaultLang == $lang) {
				$name->setRequired(true);
				$anonce->setRequired(true);
				$content->setRequired(true);
				$description->setRequired(true);
				$keywords->setRequired(true);
			}
			
			$subFormName->addElement($name);
			$subFormAnonce->addElement($anonce);
			$subFormContent->addElement($content);
			$subFormDescription->addElement($description);
			$subFormKeywords->addElement($keywords);
		}
		
		$this->addSubForm($subFormName, 'name');
		$this->addSubForm($subFormAnonce, 'anonce');
		$this->addSubForm($subFormContent, 'content');
		$this->addSubForm($subFormDescription, 'description');
		$this->addSubForm($subFormKeywords, 'keywords');
		
		$published = $this->createElement('radio','published');
		$published->setLabel(_('Published:'));
		$published->setSeparator(' ');
		$published->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$published->setValue('1');
		$published->setRequired(true);
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel(_('Save'));
		
		$this->addElement($published);
		$this->addElement($submit);
	}
}
